package search.kspatial.cn.dao;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import search.kspatial.cn.pojo.Element;
import search.kspatial.cn.pojo.Images;
import search.kspatial.cn.pojo.User;

import java.io.Serializable;
import java.util.ArrayList;

/**
 * @author KK
 * @create 2021/11/14 21:38
 * @apiNote 书签dao层
 */
public interface IElementDao extends Serializable {
    @Select("SELECT href,title,imgPath FROM element e JOIN images i ON e.id = i.id")
    ArrayList<Element> queryElements();

    @Select("SELECT * FROM element where eid='${eid}'")
    Element queryElement(@Param("eid") String eid);

    @Insert("INSERT INTO element(href,title,id,eid) VALUES(#{href},#{title},#{id},#{eid})")
    void addElement(Element element);

    @Insert("insert into user_elements(eid,uid) values('${eid}',${uid})")
    void addUser_Element(@Param("eid") String eid, @Param("uid") int uid);

    @Select("select * from images")
    ArrayList<Images> queryImages();

    @Select("SELECT href,title,imgPath FROM user_elements ue,element e,user u,images i where ue.eid = e.eid and ue.uid = (select uid from user where username = #{username}) and e.id = i.id")
    ArrayList<Element> queryUserElements(User user);

}
